﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using Models;

namespace DAL
{
    /// <summary>
    /// 美食类别
    /// </summary>
    public class foodTypeDAL
    {
        //美食类别查询
        public static DataTable selectFood()
        {
            string sql = "select * from tb_FoodType";
            return SqlDBHelper.GetDataTable(sql);
        }
        //查询数据条数
        public static object dataNum()
        {
            string sql = "select count(*) from tb_FoodType";
            return SqlDBHelper.ExecuteScalar(sql);
        }
        //美食类别模糊查询
        public static DataTable foodCX(string name)
        {
            string sql = "select * from tb_FoodType where FoodTypeName like'%" + name + "%'";
            return SqlDBHelper.GetDataTable(sql);
        }
        //美食类别添加
        public static int foodAdd(string name)
        {
            string sql = "insert into tb_FoodType(FoodTypeName) values(@FoodTypeName)";
            SqlParameter[] para = { 
            new SqlParameter("@FoodTypeName",name),
            };
            return SqlDBHelper.ExecuteNonQuery(sql,para);
        }
        //美食类别添加判断重复
        public static object foodCF(string name)
        {
            string sql = "select * from tb_FoodType where FoodTypeName='" + name + "'";
            return SqlDBHelper.ExecuteScalar(sql);
        }
        //美食类别修改
        public static int updatePay(FoodType f)
        {
            string sql = "update tb_FoodType set FoodTypeName=@FoodTypeName where FoodTypeID=@FoodTypeID";
            SqlParameter[] para = {
            new SqlParameter("@FoodTypeID",f.FoodTypeID),
            new SqlParameter("@FoodTypeName",f.FoodTypeName),
            };
            return SqlDBHelper.ExecuteNonQuery(sql,para);
        }
        //美食类别删除
        public static int delete(int id)
        {
            string sql = "delete from tb_FoodType where FoodTypeID=" + id;
            return SqlDBHelper.ExecuteNonQuery(sql);
        }
        //下拉框
        public static List<FoodType> liXlk()
        {
            string sql = "select * from tb_FoodType";
            SqlDataReader dr = SqlDBHelper.GetReader(sql);
            List<FoodType> lis = new List<FoodType>();
            while (dr.Read())
            {
                lis.Add(new FoodType()
                {
                    FoodTypeID = Convert.ToInt32(dr["FoodTypeID"]),
                    FoodTypeName = dr["FoodTypeName"].ToString()
                });
            }
            dr.Close();
            return lis;
        }
    }
}
